package railRoad;

import java.util.ArrayList;

//Singelton
public class Schedule {
	
	private static Schedule instance = new Schedule(); 
	
	ArrayList<Route> routeList;
	
	private Schedule() {
		routeList = new ArrayList<Route>();
	}
	
	public static Schedule getInstance() {
		return instance;
	}
	
	
	
	/**
	 * Method to add {@link#Route} to Schedule
	 * @param station {@link#Route} to add
	 */
	public void addRoute(Route route)
	{
		if (!routeList.contains(route))
			routeList.add(route);
	}
	
	/**
	 * Method to remove {@link#Route} from Schedule
	 * @param station {@link#Route} to remove
	 */
	public void removeRoute(Route route)
	{
		routeList.remove(route);
	}
	
	public Route getRouteAt(int index)
	{
		Route route = routeList.get(index);
		return route;
	}

	public Route getRouteById(int id)
	{
		for (Route route : routeList) {
			if (route.getRoute_id() == id)
				return route;
		}
		
		return null;
	}
	
	public int size()
	{
		return routeList.size();
	}
	
	@Override
	public String toString()
	{
		StringBuilder out = new StringBuilder("Schedule\n"); 
		for(Route route: routeList)
		{
			out.append("  " + route.toString());
		}
		
		return out.toString();
		
	}
}
